package com.ryskoo.permission.vendormanager.repository;

import com.ryskoo.framework.core.repository.BasicJPAImpl;
import com.ryskoo.permission.vendormanager.domain.StoreManagerPO;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

@Repository
public class VendorManagerJPAImpl extends BasicJPAImpl<StoreManagerPO> implements IVendorManagerRepository {

	/**
	 * 根据用户名查询管理员信息
	 * 
	 * @param userName
	 * @return
	 */
	@Override
	public StoreManagerPO getManagerByLoginName(String userName) {
		String hql = "select o from VendorManagerPO o where 1=1 and o.loginName =:loginName";
		Query q = this.getH4Session().createQuery(hql);
		q.setString("loginName", userName);
		Object object = q.uniqueResult();
		if (object != null) {
			return (StoreManagerPO) object;
		}
		return null;
	}

	/**
	 * 根据用户名查询管理员uuid
	 * 
	 * @param userName
	 * @return
	 */
	@Override
	public String getManagerUuidByLoginName(String userName) {
        String hql = "select o.uuid from VendorManagerPO o where 1=1 and o.loginName =:loginName";
		Query q = this.getH4Session().createQuery(hql);
		q.setString("loginName", userName);
		Object object = q.uniqueResult();
		if (object != null) {
			return (String) object;
		}
		return null;
	}
}
